<?php

/**
 * This is the model class for table "{{cptender}}".
 *
 * The followings are the available columns in table '{{cptender}}':
 * @property string $idcptender
 * @property string $opdate
 * @property string $cldate
 * @property string $seqdepo
 * @property string $idcpinquiry
 * @property string $cpdocumentFee
 * @property string $location
 * @property string $productdetail
 * @property string $tendername
 *
 * The followings are the available model relations:
 * @property Cpquotation[] $cpquotations
 * @property Cpinquiry $idcpinquiry0
 * @property Cptenderdocument[] $cptenderdocuments
 * @property Cptenderitem[] $cptenderitems
 */
class Cptender extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Cptender the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{cptender}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('idcpinquiry, tendername', 'required'),
			array('seqdepo', 'length', 'max'=>15),
			array('idcpinquiry, cpdocumentFee', 'length', 'max'=>10),
			array('location, productdetail', 'length', 'max'=>100),
			array('tendername', 'length', 'max'=>45),
			array('opdate, cldate', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('idcptender, opdate, cldate, seqdepo, idcpinquiry, cpdocumentFee, location, productdetail, tendername', 'safe', 'on'=>'search'),
                        array('idcpinquiry', 'validatefkeys'),
		);
	}        
        
        public function validatefkeys($attribute,$params){
               $aux = $attribute . '0';
               if(!$this->$aux)
                    $this->addError($attribute, Yii::t('application', 'Incorrect {attribute}.', array('{attribute}'=>Yii::t('application', $attribute))));
        }      
        
        
	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'cpquotations' => array(self::HAS_MANY, 'Cpquotation', 'idcptender'),
			'idcpinquiry0' => array(self::BELONGS_TO, 'Cpinquiry', 'idcpinquiry'),
			'cptenderdocuments' => array(self::HAS_MANY, 'Cptenderdocument', 'idcptender'),
			'cptenderitems' => array(self::HAS_MANY, 'Cptenderitem', 'idcptender'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idcptender' => Yii::t('application', 'Idcptender'),
			'opdate' => Yii::t('application', 'Opdate'),
			'cldate' => Yii::t('application', 'Cldate'),
			'seqdepo' => Yii::t('application', 'Seqdepo'),
			'idcpinquiry' => Yii::t('application', 'Idcpinquiry'),
			'cpdocumentFee' => Yii::t('application', 'Cpdocument Fee'),
			'location' => Yii::t('application', 'Location'),
			'productdetail' => Yii::t('application', 'Productdetail'),
			'tendername' => Yii::t('application', 'Tendername'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idcptender',$this->idcptender,true);
		$criteria->compare('opdate',$this->opdate,true);
		$criteria->compare('cldate',$this->cldate,true);
		$criteria->compare('seqdepo',$this->seqdepo,true);
		$criteria->compare('idcpinquiry',$this->idcpinquiry,true);
		$criteria->compare('cpdocumentFee',$this->cpdocumentFee,true);
		$criteria->compare('location',$this->location,true);
		$criteria->compare('productdetail',$this->productdetail,true);
		$criteria->compare('tendername',$this->tendername,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}